package cn.sciento.transfer.app.service.impl;

import cn.sciento.transfer.app.service.EventSendArchService;
import cn.sciento.transfer.domain.entity.EventSend;
import cn.sciento.transfer.domain.entity.EventSendArch;
import cn.sciento.transfer.domain.repository.EventSendArchRepository;
import cn.sciento.transfer.domain.repository.EventSendRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class EventSendArchServiceImpl implements EventSendArchService {
  @Autowired
  private EventSendRepository eventSendRepository;
  
  @Autowired
  private EventSendArchRepository eventSendArchRepository;
  
  @Transactional(rollbackFor = {Exception.class})
  public EventSendArch insertEventSendArch(EventSend eventSend) {
    EventSendArch eventSendArch = EventSendArch.getInstance(eventSend);
    this.eventSendArchRepository.insert(eventSendArch);
    this.eventSendRepository.deleteByPrimaryKey(eventSend.getEventId());
    return eventSendArch;
  }
}
